package com.tmpt.controller.action;


import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.tmpt.dto.A1OperationlogDto;
import com.tmpt.dto.A2UserDesktopDto;
import com.tmpt.dto.A2UserDto;
import com.tmpt.service.IOperationlogService;
import com.tmpt.service.ISecurityV2Service;
import com.tmpt.utils.WebUtils;

@Controller
@Scope("prototype")
public class DesktopAction extends ActionSupport{
	private Logger log = Logger.getLogger(this.getClass());
	
	private static final long serialVersionUID = 1L;
	private String menuId;
	private String text;
	private String href;
	private String desktopItemId;
	
	private String result;
	private List<Map<String,Object>> jsonArrayResult;

	@Resource private ISecurityV2Service securityV2Service;
	@Resource private IOperationlogService operationlogService;
	private A1OperationlogDto oprDtoBack = new A1OperationlogDto(WebUtils.getRequest(), A1OperationlogDto.UserTypeBack);
	 
	public String addMenu2Desktop(){
		try{
			HttpServletRequest request = WebUtils.getRequest();
			HttpSession session = request.getSession();
			A2UserDto userDto = (A2UserDto)session.getAttribute("magSystemDtoSession");
			long userId = userDto.getId();
			
			A2UserDesktopDto desktopDto = new A2UserDesktopDto();
			//desktopDto.setMenu1Id(menu1Id);
			//desktopDto.setMenu2Id(menu2Id);
			desktopDto.setMenuId(menuId);
			desktopDto.setHeight(500);
			desktopDto.setWidth(800);
			desktopDto.setHref(href);
			desktopDto.setText(text);
			desktopDto.setIcon("images/icon3d/005.png");

			System.out.println("----userId" + userId);
			securityV2Service.addMenu2Desktop(userId, desktopDto);
			this.result = "成功";
		}catch (Exception e) {
			this.result = "出错";
			e.printStackTrace();
		}
		return "jsonResult";
	}

	

	public String removeMenu2Desktop(){
		try{
			securityV2Service.removeMenu2Desktop(Long.parseLong(desktopItemId));
			this.result = "成功";
		}catch (Exception e) {
			this.result = "出错";
			e.printStackTrace();
		}
		return "jsonResult";
	}

	
	
	
	
	//====================== SET GET Method ==================
	public Logger getLog() {
		return log;
	}

	public void setLog(Logger log) {
		this.log = log;
	}

	public String getMenuId() {
		return menuId;
	}

	public void setMenuId(String menuId) {
		this.menuId = menuId;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public List<Map<String, Object>> getJsonArrayResult() {
		return jsonArrayResult;
	}

	public void setJsonArrayResult(List<Map<String, Object>> jsonArrayResult) {
		this.jsonArrayResult = jsonArrayResult;
	}

	public ISecurityV2Service getSecurityV2Service() {
		return securityV2Service;
	}

	public void setSecurityV2Service(ISecurityV2Service securityV2Service) {
		this.securityV2Service = securityV2Service;
	}

	public A1OperationlogDto getOprDtoBack() {
		return oprDtoBack;
	}

	public void setOprDtoBack(A1OperationlogDto oprDtoBack) {
		this.oprDtoBack = oprDtoBack;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}



	public String getDesktopItemId() {
		return desktopItemId;
	}



	public void setDesktopItemId(String desktopItemId) {
		this.desktopItemId = desktopItemId;
	}

	
	
	
	
	
	
	
}
